package com.anuode.entity;

import android.support.v4.app.Fragment;
import android.view.KeyEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Toast;

import com.anuode.widget.IntegrationColorPicker;

/**
 * Created by User on 2015/5/15.
 */
public class BaseFragment extends Fragment implements Invalidate, BaseActivityInterface, AdapterView.OnItemClickListener, View.OnClickListener, ColorPickerListener {
    protected  final String tag = getClass().getSimpleName();
    protected  View layout;

    public View getLayout() {
        return layout;
    }

    @Override
    public void onPicker(View view) {
        if (view.getId() == -1)
            throw new IllegalStateException("view must be id , not null");
    }

    protected void initPicker(View view, Integer... ids) {
        if (ids != null) {
            for (Integer id : ids) {
                IntegrationColorPicker v = getViewById(view, id);
                v.setActivity(this);
            }
        }
    }

    protected void initObject(Object object) {
    }

    protected <T extends View> T getViewById(View view, int viewId) {
        return (T) view.findViewById(viewId);
    }

    @Override
    public <T extends View> T getViewById(int viewId) {
        return (T)layout.findViewById(viewId);
    }

    @Override
    public void invalidate(int ftTag, Object object) {

    }

    @Override
    public void finish() {

    }

    @Override
    public void onNetWorkChange(int NetWorkType) {

    }

    @Override
    public void runOnUiThread(Runnable action) {
        getActivity().runOnUiThread(action);
    }

    @Override
    public void freash(Object obj) {

    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        return false;
    }

    @Override
    public void setTopTitle(String str) {

    }

    @Override
    public void setTopTitle(Integer id) {

    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

    }

    @Override
    public void onClick(View view) {

    }

    public void toastShowLong(final Object obj) {
        getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(getActivity(), obj.toString(), Toast.LENGTH_LONG).show();
            }
        });
    }

    public void toastShowLong(final int rId) {
        getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(getActivity(), Integer.valueOf(rId), Toast.LENGTH_LONG).show();
            }
        });
    }

    public void toastShowShort(final Object obj) {
        getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(getActivity(), obj.toString(), Toast.LENGTH_SHORT).show();
            }
        });
    }

    public void toastShowShort(final int rId) {
        getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(getActivity(), Integer.valueOf(rId), Toast.LENGTH_SHORT).show();
            }
        });
    }

    @Override
    public void showDialog() {

    }

    @Override
    public void dismissDialog() {

    }

    @Override
    public void init(Object object) {

    }
}